import 'package:my_flutter_demo/pages/xx_banner_carousel.dart';
import 'package:my_flutter_demo/exports.dart';
import 'base_widget_page.dart';


class HomePage extends StatelessWidget{
  const HomePage({Key? key}) : super(key: key);
  // 点击事件
  void tapAction(BuildContext context,HomeItem item ){
    print('${item.id}---${item.title}');
    if (item.id == 1){ // banner
      xx_push(context, BaseWidgetPage(item: item));
      // xx_push(context, xx_banner_carousel(item: item));
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Row(children: [
          Image.network(
            'http://photocq.photo.store.qq.com/psc?/a5884b44-9c25-4d7b-bea1-0db6db7e87b6/PBfbIKZtAJlvfOqE04IdJUU9zdlANM510pGG6cBwXEvmdx17iLo.fsu6iPg09Xslu11pPwgnk12vZzOC0WYrcw!!/b&bo=9QU4BK0KkAcRGdI!&rf=viewer_4',
            width: 20,
            height: 20,
            fit: BoxFit.cover,
          ),
          Text('XX Flutter Demo'),
        ])
      ),
      drawer: Drawer(
        child: ListView(
        children: [
          DrawerHeader(child: Text('Header')),
        ListTile(title: Text('Item 1')),
            ],
        )
      ),
      body: ListView.builder(
        itemCount: listHomeItem.length,
        itemBuilder: (context,index){
          final item = listHomeItem[index];
          if (item.id % 2 == 0){
            return ListTile(
              leading: ClipRRect(
                borderRadius: BorderRadius.circular(6.0),
                child: Image.network(
                  item.imageUrl,
                  width: 50,
                  height: 50,
                  fit: BoxFit.cover,
                ),
              ),
              title: Text(item.title),
              subtitle: Text(item.subTitle),
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: (){
                tapAction(context, item);
              },
            );
          }else{
            return GestureDetector(
              onTap: (){
                tapAction(context, item);
              },
              child: Container(
                margin: EdgeInsets.fromLTRB(15, 5, 15, 5),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(10)
                ),
                height: 60,
                child:Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    SizedBox(width: 5),
                    Icon(Icons.ice_skating),
                    SizedBox(width: 8),
                    Container(
                      // color: Colors.amber,
                      child:Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          SizedBox(height: 11),
                          Text(
                            item.title,
                            style:AppTextStyles.bodyText2
                          ),
                          SizedBox(width: 8),
                          Text(item.subTitle)
                        ],
                      ) ,
                    ),
                    Spacer(flex: 1),
                    Icon(Icons.arrow_forward_ios),
                    SizedBox(width: 10),
                  ],
                )
              ),
            );
          }
        },
      ),
    );
  }

}